
$(document).ready(function () {
    var search = document.getElementById("search").getAttribute("value");
    if (search == "") {
        $("#nihao").css("display", "none");
    }
    $("#flexme1").jExpand();
    $('#flexme1').flexigrid({
        buttons: [
            {
                name: '添加',
                bclass: 'add',
                onpress: test
            },
            {
                name: '删除',
                bclass: 'delete',
                onpress: test
            },
            {
                name: '全选',
                bclass: 'selectAll',
                onpress: test
            },
            {
                name: '查看所有药品',
                bclass: 'all',
                onpress: test
            },{
                name: '数据操作',
                bclass: 'data',
                onpress: test
            },
            {
                separator: true
            }
        ],
        title: "药物列表",
        height: 'auto'
    });
});
function test(com, grid) {
    if (com == '删除') {
        if (confirm('删除所选项目?')) {
            var form = document.getElementById("myform");
            form.submit();
        }
    } else if (com == '添加') {
        window.location.href = "/page/Medicine/AddMedicine.jsp";
    } else if (com == '全选') {
        var state = $("#medicinesIds").attr("checked");
        allselect(state, document.forms[1].medicinesIds);
    }else if (com == '查看所有药品') {
        window.location.href = "Medicine!loadAllMedicines.action";
    }else if (com == '数据操作') {
        window.location.href = "/page/file/data.jsp";
    }
}
/*
 *全选
 */
function allselect(allobj, items) {
    if (items.length > 0) {
        for (var i = 0; i < items.length; i++) {
            if (!items[i].disabled) {
                items[i].checked = !allobj;
            }
        }
    } else {
        if (items.disabled)items.checked = !allobj;
    }
}